package net.jiastudy.biz.datasync;

import java.util.concurrent.TimeUnit;

import org.springframework.data.redis.core.RedisTemplate;

import net.jiastudy.core.utils.SpringUtility;

public class SyncUtil {

	public static void setStudentSyncBatchCount(Integer count) {
		RedisTemplate<String, Integer> redisTemplate = SpringUtility.getBean("redisTemplate");
		redisTemplate.opsForValue().set("datasync.student.batchCount", count);
		redisTemplate.expire("datasync.student.batchCount", 600, TimeUnit.SECONDS);
	}

	public static Integer getStudentSyncBatchCount() {
		RedisTemplate<String, Integer> redisTemplate = SpringUtility.getBean("redisTemplate");
		Integer count = redisTemplate.opsForValue().get("datasync.student.batchCount");
		if (null == count) {
			return 0;
		}
		return count;
	}

	public static void decrStudentSyncBatchCount() {
		RedisTemplate<String, Integer> redisTemplate = SpringUtility.getBean("redisTemplate");
		redisTemplate.opsForValue().increment("datasync.student.batchCount", -1);
	}

	public static void setTeacherSyncBatchCount(Integer count) {
		RedisTemplate<String, Integer> redisTemplate = SpringUtility.getBean("redisTemplate");
		redisTemplate.opsForValue().set("datasync.teacher.batchCount", count);
		redisTemplate.expire("datasync.teacher.batchCount", 600, TimeUnit.SECONDS);
	}

	public static Integer getTeacherSyncBatchCount() {
		RedisTemplate<String, Integer> redisTemplate = SpringUtility.getBean("redisTemplate");
		Integer count = redisTemplate.opsForValue().get("datasync.teacher.batchCount");
		if (null == count) {
			return 0;
		}
		return count;
	}

	public static void decrTeacherSyncBatchCount() {
		RedisTemplate<String, Integer> redisTemplate = SpringUtility.getBean("redisTemplate");
		redisTemplate.opsForValue().increment("datasync.teacher.batchCount", -1);
	}
}
